/*
 * InclinometerSensor.java
 *
 * Created on 3 de septiembre de 2008, 15:22
 */

package r4p_gui;

import java.awt.Color;
import java.awt.Font;

/**
 *
 * @author  nemesis
 */
public class InclinometerSensor extends javax.swing.JPanel {

    boolean on;
    String name;
    // internationalized strings:
    String sensor_status_on;
    String sensor_status_off;
    
    /** Creates new form InclinometerSensor */
    public InclinometerSensor() {
        initComponents();
        this.on = true;
        this.name = "Inc_X";
        this.sensor_status_on = "Connected";
        this.sensor_status_off = "Disconnected";
        this.setValue(0);
        System.out.println("Inclinometer Sensor " + this.name + " started!");
    }
    
    public InclinometerSensor(boolean on, String name, String sensor_status_on, String sensor_status_off) {
        this.on = on;
        this.name = name;
        this.sensor_status_off = sensor_status_off;
        this.sensor_status_on = sensor_status_on;
        initComponents();
        this.setValue(0);
        System.out.println("Inclinometer Sensor " + this.name + " started!");
    }
    
    public void relanguage(String name, String sensor_status_on, String sensor_status_off) {
    	//initComponents();
    	this.name = name;
    	this.sensor_status_on = sensor_status_on;
    	this.sensor_status_off = sensor_status_off;
    	
    	if (this.on) {
    		Status.setText(this.sensor_status_on);
    	} else {
    		Status.setText(this.sensor_status_off);
    	}
    }
    
    public void setOn(boolean on) {
        if (on) {
            Status.setText(this.sensor_status_on);
            Status.setFont(new Font("negrita", Font.BOLD, 13));
            Status.setForeground(Color.GREEN);
            System.out.println("Sensor " + this.name + " >> Connected");
        } else {
            Status.setText(this.sensor_status_off);
            Status.setFont(new Font("normal", Font.PLAIN, 12));
            Status.setForeground(Color.RED);
            Value.setText("--");
            System.out.println("Sensor " + this.name + " >> Disconnected");
        }
	this.on = on;
    }
    
    public boolean isOn() {
        return this.on;
    }
    
    @Override
    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public String getName() {
        return this.name;
    }
    
    public void setValue(int value) {
        if (this.on) {
            this.Value.setText(Integer.toString(value) + "°");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Status = new javax.swing.JLabel();
        Value = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Inclinometer X", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 0, 10))); // NOI18N
        setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N

        Status.setFont(new java.awt.Font("DejaVu Sans", 1, 12)); // NOI18N
        Status.setForeground(java.awt.Color.green);
        Status.setText("Connected");
        Status.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                StatusMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                StatusMouseEntered(evt);
            }
        });

        Value.setFont(new java.awt.Font("DejaVu Sans", 1, 24)); // NOI18N
        Value.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Value.setText("--");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(Value, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(Status))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Status)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Value, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void StatusMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StatusMouseEntered
// TODO add your handling code here:
}//GEN-LAST:event_StatusMouseEntered

private void StatusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StatusMouseClicked
    // TODO add your handling code here:
    // changing status:
    if (this.on) {
	this.setOn(false);
    } else {
	this.setOn(true);
    }
}//GEN-LAST:event_StatusMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Status;
    private javax.swing.JLabel Value;
    // End of variables declaration//GEN-END:variables

}
